﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoAddonBiz_FreightForwarder
{
    public class B1Form_DelegateList : SAPBoAddon.B1Form
    {
        public B1Form_DelegateList()
        {
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_DelegateList_frm_ItemEvent);
        }

        void B1Form_DelegateList_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
                if (pVal.ItemUID == "7" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    CopyTo(pVal.FormUID);
                }
            }
        }

        protected override bool BeforeSaveCheckFormData()
        {
            return true;
        }

        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {

        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_FF_DelegateList;
            FormSetting.FormFileName = "AVA_FF_DelegateListForm.srf";
        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {

        }


        /// <summary>
        /// 复制到
        /// </summary>
        /// <param name="ListFormUID"></param>
        private void CopyTo(string ListFormUID)
        {
            SAPbouiCOM.Form ListForm = SBOApp.Forms.Item(ListFormUID);
            SAPbouiCOM.UserDataSource BaseEntry = ListForm.DataSources.UserDataSources.Item("BaseEntry");
            SAPbouiCOM.Grid grid = ListForm.Items.Item("Grid").Specific;
            List<string> SODEntries = new List<string>();
            for (int i = 0; i < grid.DataTable.Rows.Count; i++)
            {
                object obj = grid.DataTable.Columns.Item(0).Cells.Item(i).Value;
                if (obj.ToString() == "Y")//checkBox选中后就返回Y
                {
                    SODEntries.Add(grid.DataTable.Columns.Item(1).Cells.Item(i).Value.ToString().Trim());
                }
            }
            if (SODEntries.Count > 0)
            {
                this.ShowForm(ListForm.DataSources.UserDataSources.Item("Target").Value, ListFormUID);//this.CurrentForm.UniqueID
                //SAPbouiCOM.Form oChildForm = SAPBoAddon.B1Assistant.Form.LoadToSBOApplciation(System.Windows.Forms.Application.StartupPath + @"\Form\AVA_FF_DelegateForm.srf", "", true);
                ListForm.Close();
            }
            else
            {
                SBOApp.StatusBar.SetText(String.Format("请先勾选至少一个委托单"), SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
            }

        }
    }
}
